package com.hp.service.chain.impl;

import com.hp.model.chain.OrderRequest;
import com.hp.service.chain.ValidationHandler;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;


/**
 * @author hp
 * 第一步：用户校验
 */
@Order(1)
@Component
public class UserValidationHandler implements ValidationHandler {


    private ValidationHandler next;

    @Override
    public boolean validate(OrderRequest request) {
        // 假设用户ID 只有1-1000的ID是存在的
        if (request.getUserId() == null || request.getUserId() > 100L) {
            throw new RuntimeException("用户不存在");
        }
        return next == null || next.validate(request);
    }

    @Override
    public void setNext(ValidationHandler next) {
        this.next = next;
    }
}